package com.ruben.study;

import lombok.*;

import java.io.*;
import java.util.List;
import java.util.Optional;

/**
 * lombok学习
 *
 * @author <achao1441470436@gmail.com>
 * @since 2021/10/31 14:43
 */
@Value(staticConstructor = "VALUE")
public class LombokDemo {

    public static void main(String[] args) {
    }

    @Synchronized
    @SneakyThrows
    public static String readFile(@NonNull File file) {
        StringBuilder builder = new StringBuilder();
        @Cleanup InputStream is = new FileInputStream(file);
        String line;
        @Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        line = reader.readLine();
        while (line != null) {
            builder.append(line);
            builder.append("\n");
            line = reader.readLine();
        }
        return builder.toString();
    }

    /**
     * 这个注解： @Delegate 在我这个jdk16会报错，懒得解决了
     */
    private Optional<Integer> optional() {
        return Optional.empty();
    }

    @Builder
    @AllArgsConstructor
    @RequiredArgsConstructor(staticName = "INSTANCE")
    private static class User {
        @With
        private Integer age;
        @Singular
        private List<String> habits;
    }
}
